package io.print;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

/**
 * PrintWriter同样也可以指定输出方向
 * 1. 文件
 * 2. 控制台
 * 所以对于日志处理具有非常重要的作用
 * @author lcx
 *
 */
public class PrintWriterTest {

	public static void main(String[] args) {
		PrintWriter pw = null;
		String name = "ssss";
		int age = 22;
		float score = 32.5f;
		char sex = 'a';
		try{
			pw = new PrintWriter(new FileWriter(new File("file.txt")),true);
//			pw = new PrintWriter(System.out,true);
			pw.printf("name: %s;age: %d; sex  %c   score   %5.2f;", name,age,sex,score);
			pw.println();
			pw.println("end");
			pw.write(name.toCharArray());
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			pw.close();
		}
	}
}